function mdSwitch() {
    var mdValue = document.getElementById("md-area").value;
    var converter = new showdown.Converter();
    var html = converter.makeHtml(mdValue);
    document.getElementById("show-area").innerHTML = html;
}

function save_art() {
    var num = $(".two").attr("type");
    var title = document.getElementById("art_title").value;
    if (title.length > 50) {
        alert('标题过长，请控制在50字以内');
        return;
    }
    var classify = $('.art_classify option:selected').prop('value');
    var content = document.getElementById("md-area").value;
    var params = {
        "title": title,
        "classify": classify,
        "content": content
    };
    if (num == 0) {
        $.ajax({
            url: "/user/new_art",
            method: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.err == "0") {
                    // 刷新界面
                    alert("发布成功，即将为您跳转至用户页面");
                    location.reload();
                    window.location.href = "/user";
                } else {
                    alert(resp.errmsg);
                    get_auth_code()
                }
            }
        })

    } else {
        $.ajax({
            url: "/user/change_art/" + num,
            method: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.err == "0") {
                    // 刷新界面
                    alert("发布成功，即将为您跳转至用户页面");
                    location.reload();
                    window.location.href = "/user";
                } else {
                    alert(resp.errmsg);
                    get_auth_code()
                }
            }
        })
    }
}

function show_title_num() {
    var title_num = document.getElementById("art_title").value;
    $('#art_title').next().html('');
    $('#art_title').next().append(title_num.length+'/50')
}